1. /* slfbspr.cpp by K.Tsuru */
  2. // function ID 2011 DRADIX since ver 2.181
  3. #ifndef SN_H
  4. #include "sn.h"
  5. #endif
  6. // for sorting
  7. static int sortBySize(const void *e1, const void *e2) {
  8. return (int)((const SLong *)e2)->DFigures() - (int)((const SLong *)e1)->DFigures();
  9. }
  10. /**************************************************************************
  11. product such as
  12. a[0]a[1]...a[n-1] <-- sorted
  13. is evaluated
  14. origin (a[0]a[n-1])(a[1]a[n-2])...a[n/2]a[n/2-1] (n even) or a[n/2] (n odd)
  15. new a[0] a[1] ... a[n/2]
  16. At second step each elements has the same figures which is efficient for
  17. FFT multiplication.
  18. **************************************************************************/
  19. SLong BothSideProduct(const SNBlock <SLong>& a, const uint N, bool sort) {
  20. if(N == 1) return a(0);
  21. SLong* r = new SLong[N];
  22. for(uint i = 0; i < N ; i++) r[i] = a(i);
  23. if (sort) qsort(r, N, sizeof(SLong), sortBySize); // sort into r[0] >= r[1] >= ...
  24. uint n = N;
  25. while(n > 1) {
  26. if (sort) qsort(r, n, sizeof(SLong), sortBySize); // does not so speed up
  27. bool odd = n & 1;
  28. uint j;
  29. if(odd) {
  30. for(j = 0; j < n/2; j++) r[j] = r[j]*r[n-j-1];
  31. // r[j] == r[n/2+1];
  32. n = n/2 + 1;
  33. } else {
  34. for(j = 0; j < n/2; j++) r[j] = r[j]*r[n-j-1];
  35. n = n/2;
  36. }
  37. }
  38. SLong R(r[0]);
  39. delete[] r;
  40. return R;
  41. }

slfbspr.cpp : last modifiled at 2016/08/03 11:06:19(1,352 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).